home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / Other Langs / Tickle-4.0 (tcl) / tcl / extend / osSupport / system.c < prev   
Encoding:
C/C++ Source or Header  |  1993-10-26  |  1.9 KB  |  58 lines  |  [TEXT/MPS ]

  1. /* 
  2.  * system.c --
  3.  *
  4.  *  Version of "system" library routine for versions of Unix that have a
  5.  * system function that uses wait instead of waitpid.  These versions are
  6.  * broken, file a bug report with your vendor and use this one.  If your
  7.  * Unix does not have waitpid, this uses the simuated one supplied with
  8.  * UCB Tcl.
  9.  *-----------------------------------------------------------------------------
  10.  * Copyright 1991-1993 Karl Lehenbauer and Mark Diekhans.
  11.  *
  12.  * Permission to use, copy, modify, and distribute this software and its
  13.  * documentation for any purpose and without fee is hereby granted, provided
  14.  * that the above copyright notice appear in all copies.  Karl Lehenbauer and
  15.  * Mark Diekhans make no representations about the suitability of this
  16.  * software for any purpose.  It is provided "as is" without express or
  17.  * implied warranty.
  18.  *-----------------------------------------------------------------------------
  19.  * $Id: system.c,v 1.2 1993/08/13 15:01:21 markd Exp $
  20.  *-----------------------------------------------------------------------------
  21.  */
  22.  
  23. #include "tclExtdInt.h"
  24.  
  25. /*
  26.  *-----------------------------------------------------------------------------
  27.  *
  28.  * system --
  29.  *     Does the equivalent of the Unix "system" library call, but uses waitpid
  30.  * to wait on the correct process, rather than waiting on all processes and
  31.  * throwing the exit statii away for the processes it isn't interested in.
  32.  *-----------------------------------------------------------------------------
  33.  */
  34. int 
  35. system (command)
  36.     CONST char  *command;
  37. {
  38.     pid_t            processID;
  39.     WAIT_STATUS_TYPE processStatus;
  40.  
  41.     processID = fork ();
  42.     if (processID < 0)
  43.         return -1;
  44.  
  45.     if (processID == 0) {
  46.         execl ("/bin/sh", "sh", "-c", command, (char *) NULL);
  47.         _exit (256);
  48.     }
  49.  
  50.     /*
  51.      * Parent process.
  52.      */
  53.     if (waitpid (processID, &processStatus, 0) == -1)
  54.         return -1;
  55.  
  56.     return (WEXITSTATUS (processStatus));
  57. }
  58.